package cn.itrip.service.impl;

import cn.itrip.entity.ItripImage;
import cn.itrip.dao.ItripImageDao;
import cn.itrip.service.ItripImageService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 图片表(ItripImage)表服务实现类
 *
 * @author makejava
 * @since 2022-04-14 22:34:58
 */
@Service("itripImageService")
public class ItripImageServiceImpl implements ItripImageService {
	@Resource
	private ItripImageDao itripImageDao;

	/**
	 * 通过ID查询单条数据
	 *
	 * @param id 主键
	 * @return 实例对象
	 */
	@Override
	public ItripImage queryById(Long id) {
		return this.itripImageDao.queryById(id);
	}

	/**
	 * 分页查询
	 *
	 * @param itripImage  筛选条件
	 * @param pageRequest 分页对象
	 * @return 查询结果
	 */
	@Override
	public Page<ItripImage> queryByPage(ItripImage itripImage, PageRequest pageRequest) {
		long total = this.itripImageDao.count(itripImage);
		return new PageImpl<>(this.itripImageDao.queryAllByLimit(itripImage, pageRequest), pageRequest, total);
	}

	/**
	 * 新增数据
	 *
	 * @param itripImage 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripImage insert(ItripImage itripImage) {
		this.itripImageDao.insert(itripImage);
		return itripImage;
	}

	/**
	 * 修改数据
	 *
	 * @param itripImage 实例对象
	 * @return 实例对象
	 */
	@Override
	public ItripImage update(ItripImage itripImage) {
		this.itripImageDao.update(itripImage);
		return this.queryById(itripImage.getId());
	}

	/**
	 * 通过主键删除数据
	 *
	 * @param id 主键
	 * @return 是否成功
	 */
	@Override
	public boolean deleteById(Long id) {
		return this.itripImageDao.deleteById(id) > 0;
	}
}
